let interstitialAd = null
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiper: {
      indicatorDots: true,
      autoplay: true,
      interval: 5000,
      duration: 1000,
      lrmargin: "40rpx",
      easing: "easeInOutCubic",
      activeColor: "#fff",
      color: "rgba(255, 255, 255, .3)"
    },
    adsetting: {
      indicatorDots: true,
      autoplay: true,
      interval: 10000,
      duration: 1000,
      lrmargin: "30rpx",
      easing: "easeInOutCubic",
      activeColor: "#fff",
      color: "rgba(255, 255, 255, .3)"
    },

    // 广告
    imgUrls: [{
      img: '../../images/ad/ad1.jpg',
      openpath: "../../pages/weather/weather",
    },
    {
      img: '../../images/ad/ad1.jpg',
      openpath: "../../pages/weather/weather",
    }
  ],
    // 推荐
    recommend: [{
      img: "../../images/toolIcon/weather.png",
      openpath: "../../pages/weather/weather",
      text: "天气"
    },
    {
      img: "../../images/toolIcon/qrcode.png",
      openpath: "../../pages/qrcode/index",
      text: "生成二维码"
    },
    {
      img: "../../images/toolIcon/IP.png",
      openpath: "../../pages/IP/IP",
      text: "IP地址查询"
    },
    {
      img: "../../images/toolIcon/hl.png",
      openpath: "../../pages/cand/index",
      text: "程序员黄历"
    }],
    // 工具列表
    server: [
      {
        img: "../../images/toolIcon/sdm.png",
        openpath: "../../pages/christmasHat/index/index",
        text: "圣诞帽"
      },
      {
        img: "../../images/toolIcon/qrcode.png",
        openpath: "../../pages/qrcode/index",
        text: "生成二维码"
      },
      {
        img: "../../images/toolIcon/wsyt.png",
        openpath: "../../pages/gojuuonn/gojuuonn",
        text: "五十音图"
      },
      {
        img: "../../images/toolIcon/cha.png",
        openpath: "../../pages/pinyin/index",
        text: "查拼音"
      },
      {
        img: "../../images/toolIcon/clac.png",
        openpath: "../../pages/calc/index",
        text: "计算器"
      },
      {
        img: "../../images/toolIcon/hl.png",
        openpath: "../../pages/cand/index",
        text: "程序员黄历"
      },
      {
        img: "../../images/toolIcon/gz.png",
        openpath: "../../pages/game/game",
        text: "摇骰子"
      },
      {
        img: "../../images/toolIcon/sc.png",
        openpath: "../../pages/figure/figure",
        text: "身材计算"
      },
      {
        img: "../../images/toolIcon/weather.png",
        openpath: "../../pages/weather/weather",
        text: "天气"
      },
      {
        img: "../../images/toolIcon/IP.png",
        openpath: "../../pages/IP/IP",
        text: "IP地址查询"
      },
      {
        img: "../../images/toolIcon/MobileHome.png",
        openpath: "../../pages/MobileHome/MobileHome",
        text: "手机归属地"
      },
      {
        img: "../../images/toolIcon/codePars.png",
        openpath: "../../pages/codePars/codePars",
        text: "电码查询"
      },
      {
        img: "../../images/toolIcon/historyToday.png",
        openpath: "../../pages/historyToday/historyToday",
        text: "历史今天"
      },
      {
        img: "../../images/toolIcon/shudu.png",
        openpath: "../../pages/shudu/shudu",
        text: "数独"
      },
      {
        img: "../../images/toolIcon/xiao_1.png",
        openpath: "../../pages/xiaohua/xiao",
        text: "每日一笑"
      },
      {
        img: "../../images/toolIcon/birth.png",
        openpath: "../../pages/birth/birth",
        text: "卜生辰"
      },
      {
        img: "../../images/toolIcon/car.png",
        openpath: "../../pages/car/car",
        text: "汽车故障码查询"
      },
      {
        img: "../../images/toolIcon/money.png",
        openpath: "../../pages/money/money",
        text: "贷款公积金计算"
      },
    ],
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showShareMenu({
      menus: ['shareAppMessagewx', 'shareTimeline'],
      withShareTicket: true
    });
    this.showAD()
  },
  showAD(){
    console.log("广告")
    if(wx.createInterstitialAd){
      console.log("广告")
      interstitialAd = wx.createInterstitialAd({ adUnitId: 'adunit-7131d9962cb84583' })
      interstitialAd.onLoad(() => {
        console.log('onLoad event emit')
      })
      interstitialAd.onError((err) => {
        console.log('onError event emit', err)
      })
      interstitialAd.onClose((res) => {
        console.log('onClose event emit', res)
      })
    }
  },
  /**
     * 生命周期函数--监听页面显示
     */
  onShow: function () {
    // 获取轮播
    this.getADList()
  },

  // 获取轮播
  getADList() {
    let that = this
    wx.cloud.callFunction({
      name: 'getADList',
      data: {
        adType: 'index'
      }
    }).then(res => {
      console.log(res)
      that.setData({
        imgUrls: res.result.data
      })
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: "口袋工具箱-一个多功能工具箱",
      path: 'pages/index/index'
    };
  },
  /**
   * 分享朋友圈
   */
  onShareTimeline: function () {
    return {
      title: '口袋工具箱-一个多功能工具箱',
      imageUrl: '../../images/share.jpg'
    }
  },
})